<template>
  <div class="rightBodyContent">
    <div class="rightBodyContent-in">
      <div class="mb-10">
        <div class="toplineBox">
          <div class="toplineBox-left">
            <el-input v-model="realname" placeholder="姓名" size="small w-140" class="mr-10"></el-input>
            <el-select v-model="typeFood" placeholder="选择类型" size="small" class="mr-10">
              <el-option
                v-for="item in listSelect"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
            <el-date-picker type="date"
                            placeholder="选择日期"
                            v-model="getTime"
                            size="small"
                            value-format="yyyy-MM-dd"></el-date-picker>
            <el-button type="primary" size="small" @click="searchFn('search')" class="ml-10"><i
              class="el-icon-search"></i>搜索
            </el-button>
            <el-button size="small" @click="refreshFn()"><i class="el-icon-refresh"></i>重置刷新</el-button>
          </div>
          <p class="numberline toplineBox-right">总{{page.total}}条</p>
        </div>
      </div>
      <!--本体列表，数据 -->
      <div class="table-body">
        <div class="table-body-box">
          <el-table
            ref="multipleTable"
            :data="arryList"
            :stripe="tableStyle.tableStripe"
            :border="tableStyle.tableBorder"
            tooltip-effect="dark"
            style="width: 100%"
            header-cell-class-name="table-text-c"
            cell-class-name="table-text-c"
          >
            <el-table-column
              label="姓名">
              <template slot-scope="scope">
                {{scope.row.student?scope.row.student.name: ''}}
              </template>
            </el-table-column>
            <el-table-column
              label="班级">
              <template slot-scope="scope">
                {{scope.row.classes?scope.row.classes.class_name: ''}}
              </template>
            </el-table-column>
            <el-table-column
              label="餐品">
              <template slot-scope="scope">
                <el-tag
                  :key="`${tag.id}`"
                  v-for="(tag, index) in scope.row.dish_ids"
                  class="mr-10 tag-box"
                >{{ tag.name }}
                </el-tag>
              </template>
            </el-table-column>

            <el-table-column
              label="类型">
              <template slot-scope="scope">
                {{listType[scope.row.type]}}
              </template>
            </el-table-column>
            <el-table-column
              prop="number"
              label="光盘值">
            </el-table-column>
            <el-table-column
              prop="day"
              label="光盘时间">
            </el-table-column>
<!--            <el-table-column-->
<!--              prop="update_time"-->
<!--              label="创建时间">-->
<!--            </el-table-column>-->
            <el-table-column
              label="操作">
              <template slot-scope="scope">
                <el-button size="small" @click="detelFn(scope.row.id,scope.$index)" type="danger" plain>删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <!--工具条 分页-->
      <el-col :span="24" class="toolbar">
        <el-pagination
          background
          layout="total, prev, pager, next"
          :total="page.total"
          :page-size="page.pagesize"
          @current-change="handleSizeChange">
        </el-pagination>
      </el-col>
    </div>
  </div>
</template>

<script>
import {pagination, tableoption} from '@/utils/util.js'
import {
  plate_student,
  plate_student_delete
} from "@/api/admin/food"

export default {
  components: {
  },
  data () {
    return {
      arryList: [],
      handleSelection: [],
      // 设置table样式
      tableStyle: tableoption,
      // 设置table页面分页所需
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      detailVisible: false,
      editId: 0,
      addvisible: false,
      detailvisible: false,
      wagesDetail: null,
      listSelect:[
        {
          id: 1,
          name: '早点'
        },
        {
          id: 2,
          name: '午餐'
        },
        {
          id: 4,
          name: '水果'
        },
        {
          id: 3,
          name: '午点'
        }
      ],
      getTime: '',
      typeFood: '',
      realname: '',
      listType:{
        1:'早点',
        2:'午餐',
        4:'水果',
        3:'午点',
      }
    }
  },
  created () {
    this.InitFn()
  },
  methods: {
    // 初始化
    InitFn () {
      plate_student({
        p: this.page.pageindex,
        day: this.getTime,
        type: this.typeFood,
        name: this.realname
      }).then(res=>{
        this.arryList = res.list.data
        this.page.total = res.list.total
      })
    },
    checkIdCard () {
      this.changeCartVisible = true
    },
    handleSelectionChange (val) {
      this.handleSelection = val
    },
    // 分页
    handleSizeChange (val) {
      this.page.pageindex = val
      this.InitFn()
    },
    // 刷新页面
    searchFn() {
      this.page.pageindex = 1
      this.InitFn()
    },
    // 刷新页面
    refreshFn() {
      this.page.pageindex = 1
      this.getTime = ''
      this.typeFood = ''
      this.realname = ''
      this.InitFn()
    },
    addStudent (option) {
      this.wagesDetail = JSON.parse(JSON.stringify(option))
      this.detailvisible = true
    },
    detelFn (id) {
      let self_ = this
      this.$confirm('确认删除此数据，是否继续？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        plate_student_delete({
          id: id
        }).then(res => {
          this.$message.success('删除成功')
          this.InitFn()
        })
      }).catch(() => {

      })
    }
  },
  mounted () {
  }
}
</script>
